var app = getApp(),
  $ = require("../../utils/httpHelper.js")
var wxParse = require("../../wxParse/wxParse.js")
Page({
  data: {
    userInfo: {},
    size:['1','2','3','4','5'],
    page: 1,
    pagesize: 10,
    totalpage: 0,//最大页数,
    tempFilePaths:'',
    filepathArr:[],
    width:0,
    coll:false,
    num:0,
    orderno:'',
    cont:''
  },
  onLoad: function (options) {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        that.setData({ width: 3*(res.windowWidth-40)/10  })
      }
    })
    console.log(options)
    if (!app.check_empty(options.orderno)){
      this.setData({
        orderno: options.orderno
      })
    }
  },
  oncont(e){
    let value = e.detail.value
    this.setData({
      num:value.length,
      cont:value
    })
  },
  tij(){
    if (!app.check_empty(this.data.cont)){
      let params = {
        rd_session: app.globalData.userInfo.rd_session,
        order_no: this.data.orderno,
        content: this.data.cont
      }
      $.httpPost('comment_order', params, (data, err) => {
        if(data.result == 'success'){
          wx.navigateTo({
            url: '/pages/mine/mine',
          })
        }
      })
    }else{
      wx.showToast({
        title: '不能是空',
      })
    }
  },

  //滑动到底部 上拉加载
  scrollBottom: function () {
    this.data.page++
    if (this.data.page > this.data.totalpage) {
      this.setData({
        nomore: false
      })
    } else {
      let params = {
        rd_session: app.globalData.userInfo.rd_session,
        page: this.data.page,
        pagesize: this.data.pagesize,
        status: this.data.status
      }
      $.httpPost('order_list', params, (data, err) => {
        let arr = this.data.objarr;
        for (let item of data.data.order_list) {
          arr.push(item);
        }
        this.setData({
          objarr: arr
        })
      })


    }

  },
  
  chooseimage: function (e) {
    var that = this;
    console.log(that.data.filepathArr.length)
    if (that.data.filepathArr.length > 5){
      wx.showToast({
        title: '不能超过六张',
      })
      return;
    }
    wx.showActionSheet({
      itemList: ['从相册中选择', '拍照'],
      itemColor: "#9C0097",
      success: function (res) {
        if (!res.cancel) {
          if (res.tapIndex == 0) {
            that.chooseWxImage('album')
          } else if (res.tapIndex == 1) {
            that.chooseWxImage('camera')
          }
        }
      }
    })

  },

  chooseWxImage: function (type) {
    var that = this;
    wx.chooseImage({
      sizeType: ['original', 'compressed'],
      sourceType: [type],
      success: function (res) {
        //去上传
        // var tempFilePaths = res.tempFilePaths
        // wx.uploadFile({
        //   url: 'http://example.weixin.qq.com/upload', //仅为示例，非真实的接口地址
        //   filePath: tempFilePaths[0],
        //   name: 'file',
        //   formData: {
        //     'user': 'test'
        //   },
        //   success: function (res) {
        //     var data = res.data
        //     //do something
        //   }
        // })
        console.log(res);
        let arr = that.data.filepathArr
        arr.push(res.tempFilePaths[0])
        that.setData({
          tempFilePaths: res.tempFilePaths[0],
          coll:true,
          filepathArr:arr
        })
      }
    })
  }
  
});